<?php
include "include/config.inc.php";
$interestToPay = array();
$i=0;
$j = 0;
$totle = 0;
$today = date("Y-m-d");
if(isset($_POST['submitDate']))
{
  $fromDate = date("Y-m-d");
	$toDate   = $_POST['toDateYear'].'-'.$_POST['toDateMonth'].'-'.$_POST['toDateDay'];
  $selInterestToPay = "SELECT transaction.transactionId, transaction.accountIdCr, account.accountName, transaction.amount, transaction.pendingAmount, 
                              transaction.interest30days, transaction.transDate
                         FROM transaction
                         JOIN account ON transaction.accountIdCr = account.accountId
                        WHERE transaction.interest30days > 0
                          AND transaction.pendingAmount > 0";
  $selInterestToPayRes = mysql_query($selInterestToPay);
  while($selInterestToPayRow = mysql_fetch_array($selInterestToPayRes))
  {
  	$selInterestToPayRow['transDate'];
  	$currentDate = date('Y-m-d',strtotime('+30 day',strtotime($selInterestToPayRow['transDate'])));
  	
  	while($currentDate <= $toDate)
  	{
      if($currentDate >= $fromDate)
      {
        $interestToPay[$j]['transactionId']  = $selInterestToPayRow['transactionId'];
        $interestToPay[$j]['accountIdCr']    = $selInterestToPayRow['accountIdCr'];
        $interestToPay[$j]['accountName']    = $selInterestToPayRow['accountName'];
        $interestToPay[$j]['interest30days'] = (($selInterestToPayRow['interest30days']*$selInterestToPayRow['pendingAmount'])/$selInterestToPayRow['amount']);
        $interestToPay[$j]['transDate']      = date("d-m-Y",strtotime($currentDate));
        $totle = $totle + $interestToPay[$j]['interest30days']; 
        $j++;
      }
      $currentDate = date('Y-m-d',strtotime('+30 day',strtotime($currentDate)));
    }
  }
}
$smarty->assign('today',$today);
$smarty->assign('totle',$totle);
$smarty->assign('interestToPay',$interestToPay);
$smarty->display('interestToPay.tpl');
?>